// scaup - Scala up!
// (c) 2008-2010, Normen Müller, normen.mueller@gmail.com  
// $Id: JNAUtil.scala 80 2010-05-13 12:31:58Z normen.mueller $
package scaup.io.jna

import java.io._
import scaup.io.FileType._

/**
 *  @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 *  @version 0.0.5
 */
private[io] object JNAUtil {  
  private val loader = 
    try {
      val l = JNAUtil.getClass.getClassLoader
      if (l == null) ClassLoader.getSystemClassLoader else l
    } catch {
      case e: ClassNotFoundException => null
    }
  
  private val isJNAPresent = if(loader != null && loader.loadClass("com.sun.jna.Library") != null) true else false   
  
  // linux.
  
  def getFileType(file: File) = if(isJNAPresent) LinuxUtil.getFileType(file) else NONE
  
  def getLinkTarget(file: File) = if(isJNAPresent) LinuxUtil.getLinkTarget(file) else None
  
  def createSymlink(file: Option[File], linkName: String) = if (isJNAPresent) LinuxUtil.createSymlink(file, linkName) else None
  
  def isExecutable(file: File) = if(isJNAPresent) LinuxUtil.isExecutable(file) else false
  
  def setExecutable(file: File, set: Boolean) = if(isJNAPresent) LinuxUtil.setExecutable(file, set) else false
  
  def setWritable(file: File, set: Boolean) = if(isJNAPresent) LinuxUtil.setWritable(file, set) else false
  
  def setSGID(file: File) = if(isJNAPresent) LinuxUtil.setSGID(file) else false  
}
